<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

// 修改为匿名类，避免类名冲突
return new class extends Migration
{
    public function up()
    {
        Schema::create('order_items', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id')->comment('订单ID');
            $table->unsignedBigInteger('product_id')->comment('商品ID');
            $table->string('product_name')->comment('商品名称');
            $table->string('variant')->nullable()->comment('商品规格');
            $table->string('image')->nullable()->comment('商品图片');
            $table->unsignedInteger('quantity')->default(1)->comment('购买数量');
            $table->decimal('price', 10, 2)->comment('商品单价');
            $table->unsignedBigInteger('verification_code_id')->nullable()->comment('验证码ID');
            $table->timestamps();

            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
            $table->foreign('product_id')->references('id')->on('products');
        });
    }

    public function down()
    {
        Schema::dropIfExists('order_items');
    }
};

// 此文件与 2025_07_06_130000_create_order_items_table.php 功能重复，请直接删除本文件。
